using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Services.TfsAlert.AppCode;
using Microsoft.Services.TfsAlert.AppCode.NotificationEvents;
using Microsoft.Services.TfsAlert.Core;

namespace Microsoft.Services.TfsAlert
{
    [TestClass]
    public class NotificationReciever_UnitTests
    {
        [TestMethod]
        public void DoesNotifyEventFireWhenNotificationRecieverNotifyIsCalled()
        {
            bool notificationEventCalled = false;
            string workItemChangedEventMessageString = null;

            WorkItemChangedEvent workItemChangedEvent = new WorkItemChangedEvent();

            ApplicationHelpers applicationHelpers = new ApplicationHelpers();
            workItemChangedEventMessageString =
                applicationHelpers.SerializeXml<WorkItemChangedEvent>( workItemChangedEvent );

            NotificationReciever.MessageAlert += (MessageAlertDelegate)delegate( object obj, MessageAlertEventArgs e )
                                                                           {
                                                                               notificationEventCalled = true;
                                                                           };

            NotificationReciever notificationReciever = new NotificationReciever();
            notificationReciever.Notify(workItemChangedEventMessageString, "FooBar Identity", new SubscriptionInfo());

            Assert.IsTrue( notificationEventCalled,
                           "Expected the the event NotificationReciever.TfsNotify to fire when calling NotificationReciever.Notify" );
        }
    }
}